<template>
  <div class="tab">
    <div class="tab-item" v-for="(item, index) of tabData" :key="index">
      <!-- 
      {
        iconText: '明',
        tabText: '明天',
        path: '/tomorrow'
      }
     -->
      <tab-icon :iconText="item.iconText" :path="item.path">
        {{ item.tabText }}
      </tab-icon>
    </div>
  </div>
</template>

<script>
import tabData from "../../datas/tab";
import TabIcon from "./Icon.vue";

//手动创建响应式对象
//toRefs: 用于包裹state
import { reactive, toRefs } from "vue";

export default {
  name: "Tab",
  components: {
    TabIcon,
  },
  setup() {
    const state = reactive({ tabData });
    // console.log(state);
    //Proxy {tabData: Array(5)}

    /**
     * console.log({ ...state });
     * {
     *   tabData: Proxy
     *     [[Handler]]: Object
     *     [[Target]]: Array(5)
     *     [[IsRevoked]]: false
     * }
     */

    /**
     * console.log({ ...toRefs(state) });
     * {
     *   tabData: ObjectRefImpl{
     *     __v_isRef: true
     *     _key: "tabData"
     *     _object: Proxy {tabData: Array(5)}
     *     value: Proxy
     *   }
     * }
     */

    return {
      //平铺 相当于 return { tabData }
      // ...state,
      ...toRefs(state),
    };
  },
};
</script>

<style lang="scss" scoped>
.tab {
  display: flex;
  flex-direction: row;
  position: fixed;
  bottom: 0;
  left: 0;
  z-index: 1;
  width: 100%;
  height: 0.44rem;
  border-top: 1px solid #ddd;
  background-color: #fff;

  .tab-item {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 33.33%;
    height: 100%;
  }
}
</style>